const User = require('./User');
const Scam = require('./Scam');
const Comment = require('./Comment');

// User - Scam 关联
User.hasMany(Scam, {
  foreignKey: 'userId',
  as: 'scams'
});
Scam.belongsTo(User, {
  foreignKey: 'userId',
  as: 'author'
});

// User - Comment 关联
User.hasMany(Comment, {
  foreignKey: 'userId',
  as: 'comments'
});
Comment.belongsTo(User, {
  foreignKey: 'userId',
  as: 'author'
});

// Scam - Comment 关联
Scam.hasMany(Comment, {
  foreignKey: 'scamId',
  as: 'comments'
});
Comment.belongsTo(Scam, {
  foreignKey: 'scamId',
  as: 'scam'
});

// Comment 自关联（用于二级评论）
Comment.hasMany(Comment, {
  foreignKey: 'parentId',
  as: 'replies'
});
Comment.belongsTo(Comment, {
  foreignKey: 'parentId',
  as: 'parent'
});

module.exports = {
  User,
  Scam,
  Comment
}; 